﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Aliyeye.Car.Net.UI.Common;

namespace Aliyeye.Car.Net.UI.SystemModel
{
    public partial class PointsRate : Form
    {
        public PointsRate()
        {
            InitializeComponent();
        }

        private void menuBlueButton2_Click(object sender, EventArgs e)
        {
            this.Close();
        }



        private void btnOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtRate.Text))
            {
                PageCommon.Alert("会员积分比率不能为空！");
                return;
            }

            //--佣金比例
            float CommissionRatio = 0;
            if (!string.IsNullOrEmpty(this.txtRate.Text))
            {
                try
                {
                    CommissionRatio = float.Parse(this.txtRate.Text);
                    if (CommissionRatio < 0)
                    {
                        PageCommon.Alert("会员积分比率不能为负数！");
                        return;
                    }
                }
                catch
                {
                    PageCommon.Alert("请填入正确会员积分比率,如：0.25！");
                    return;
                }
            }

            overlay.FadeIn(); Cursor.Current = Cursors.WaitCursor;
            ArchivesSvc.SoapHeaderClass sopaHeader = new ArchivesSvc.SoapHeaderClass();

            ServiceManipulator.SafeAsyncExecution<ArchivesSvc.ArchivesServiceSoapClient>(
                proxy => proxy.UpdatePointRate(sopaHeader, CommissionRatio.ToString()),
                result =>
                {
                    if (result.Error == null)
                    {
                        PageCommon.Notify("更新成功！");
                        overlay.FadeOut(); Cursor.Current = Cursors.Default;
                    }
                    else
                    {
                        PageCommon.Error(result.Error.Message); overlay.FadeOut(); Cursor.Current = Cursors.Default;
                    }
                },
                this
            );
        }

        private void PointsRate_Load(object sender, EventArgs e)
        {
            overlay.FadeIn(); Cursor.Current = Cursors.WaitCursor;
            ArchivesSvc.SoapHeaderClass sopaHeader = new ArchivesSvc.SoapHeaderClass();

            ServiceManipulator.SafeAsyncExecution<ArchivesSvc.ArchivesServiceSoapClient>(
                proxy => proxy.GetPointsRate(sopaHeader),
                result =>
                {
                    if (result.Error == null)
                    {
                        txtRate.Text = result.Result.ToString();
                        overlay.FadeOut(); Cursor.Current = Cursors.Default;
                    }
                    else
                    {
                        PageCommon.Error(result.Error.Message); overlay.FadeOut(); Cursor.Current = Cursors.Default;
                    }
                },
                this
            );
        }
    }
}
